package org.schedule.common;

import java.time.LocalDateTime;

public class ApiResponse<T> {
    private int code;          // 响应码
    private String message;    // 响应消息
    private T data;           // 响应数据
    private LocalDateTime timestamp; // 响应时间戳

    public ApiResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.timestamp = LocalDateTime.now();
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public LocalDateTime getTimestamp() {
        return timestamp;
    }

    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(200, "Success", data);
    }

    public static <T> ApiResponse<T>  error(int code, String message) {
        return new ApiResponse<>(code, message, null);
    }
}
